package com.xhx.controller;

import javax.annotation.Resource;

import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.xhx.context.FlowContext;
import com.xhx.vo.ApplyFlowVO;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;

@RestController
@RequestMapping("/flow")
public class FlowController {
    @Resource
    private FlowExecutor flowExecutor;

    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    @ResponseBody
    public FlowContext submit(@Nullable @RequestBody ApplyFlowVO param) {
        try {
            LiteflowResponse response = flowExecutor.execute2Resp("mainChain", param, FlowContext.class);
            return response.getContextBean(FlowContext.class);
        } catch (Throwable t) {
            t.printStackTrace();
            return null;
        }
    }

}
